from typing import List
from collections import defaultdict


class Solution:
    def minRecSize(self, lines: List[List[int]]) -> float:
        if len(lines) <= 2:
            return 0

        lines = [line.copy() for line in lines]
        lines_grouped = defaultdict(list)
        for k, b in lines:
            lines_grouped[k].append(b)
        lines_grouped = sorted(lines_grouped.items())
        if len(lines_grouped) <= 1:
            return 0
        points = []

        def gcd(x, y):
            if x == 0:
                return (0, 1)

            if y < 0:
                x *= -1
                y *= -1

            x_ = abs(x)
            y_ = abs(y)
            while True:
                if y_ > x_:
                    x_, y_ = y_, x_
                if x_ % y_ == 0:
                    break
                x_ = x_ % y_
            x //= y_
            y //= y_
            return (x, y)

        for i in range(len(lines_grouped) - 1):
            j = i + 1
            k1, bs1 = lines_grouped[i]
            if len(bs1) > 2:
                bs1 = [min(bs1), max(bs1)]
            k2, bs2 = lines_grouped[j]
            if len(bs2) > 2:
                bs2 = [min(bs2), max(bs2)]
            for b1 in bs1:
                for b2 in bs2:
                    x = gcd((b2 - b1), (k1 - k2))
                    y = gcd((k1 * b2 - b1 * k2), (k1 - k2))
                    points.append((x, y))

        points = set(points)
        if len(points) < 1:
            return 0
        points = [[p[0][0] / p[0][1], p[1][0] / p[1][1]] for p in points]
        left = min(p[0] for p in points)
        right = max(p[0] for p in points)
        up = min(p[1] for p in points)
        down = max(p[1] for p in points)
        area = abs((up - down) * (right - left))
        return area